package com.woniu.service.impl;

import com.woniu.entity.vo.ChapterVO;
import com.woniu.entity.vo.VideoVO;
import com.woniu.mapper.VideoMapper;
import com.woniu.pojo.Chapter;
import com.woniu.mapper.ChapterMapper;
import com.woniu.service.IChapterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程章节表 服务实现类
 * </p>
 *
 * @author xiaotang
 * @since 2023-07-25
 */
@Service
public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> implements IChapterService {

    @Autowired
    private ChapterMapper chapterMapper;
    @Autowired
    private VideoMapper videoMapper;

    @Override
    public List<ChapterVO> listByCourseIdRelationVideos(Long courseId) {
        // 1. 根据课程ID查询章节信息
        List<ChapterVO> chapterVOList = chapterMapper.selectByCourseId(courseId);
        // 2. 根据章节ID查询视频的数据,并且把视频数据设置到章节中
        for(ChapterVO chapterVO : chapterVOList){
            List<VideoVO> videoVOList = videoMapper.selectByChaterId(chapterVO.getId());
            chapterVO.setVideoVOList(videoVOList);
        }
        // 3. 返回数据
        return chapterVOList;
    }

}